package com.financing.components.push;
import com.financing.components.push.android.AndroidBroadcast;
import com.financing.components.push.ios.IOSBroadcast;

public class AppPushUtil {
	private String appkey = null;
	private String appMasterSecret = null;
	private PushClient client = new PushClient();
	
	public AppPushUtil(String key, String secret) {
		try {
			appkey = key;
			appMasterSecret = secret; 
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
	
	public void sendAndroidBroadcast(String title, String contents) throws Exception {
		AndroidBroadcast broadcast = new AndroidBroadcast(appkey,appMasterSecret);
		broadcast.setTicker("Android broadcast ticker");
		broadcast.setTitle(title);
		broadcast.setText(contents);
		broadcast.goAppAfterOpen();
		broadcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
		broadcast.setProductionMode();
		client.send(broadcast);
	}
	
	public void sendIOSBroadcast(String title, String contents) throws Exception {
		IOSBroadcast broadcast = new IOSBroadcast(appkey,appMasterSecret);
		broadcast.setAlert(title);
		broadcast.setBadge(0);
		broadcast.setSound("default");
		broadcast.setProductionMode();
		//broadcast.setTestMode();
		// TODO set 'production_mode' to 'true' if your app is under production mode
		//broadcast.setTestMode();
		// Set customized fields
		// broadcast.setCustomizedField("test", "helloworld");
		client.send(broadcast);
	}
}
